

// 首页滚动模块显示
$(function(){
	var $nav = $(".p_topnavbox")/*,
		$hotbox01 = $(".p_in_hotlpbox"),
		$hotbox02 = $(".p_in_hothxbox"),
		$hotbox03 = $(".p_in_shejis")*/;
	/*if($hotbox01.length>0){
		var offBtm01 = $hotbox01.offset().top+$hotbox01.height();
	}
	if($hotbox02.length>0){
		var offBtm02 = $hotbox02.offset().top+$hotbox02.height()-100;
	}
	if($hotbox03.length>0){
		var offBtm03 = $hotbox03.offset().top+$hotbox03.height();
	}*/
	var wHeight = $(window).height();
	/*if($(window).scrollTop() + wHeight >= offBtm01){
			$hotbox01.addClass("pageShow");
	}
	if($(window).scrollTop() + wHeight >= offBtm02){
			$hotbox02.addClass("pageShow");
	}
	if($(window).scrollTop() + wHeight >= offBtm03){
			$hotbox03.addClass("pageShow");
	}*/
	$(window).bind("scroll",function(){
		//首页动画
		/*if($(window).scrollTop() + wHeight >= offBtm01){
			$hotbox01.addClass("pageShow");
		}
		if($(window).scrollTop() + wHeight >= offBtm02){
			$hotbox02.addClass("pageShow");
		}
		if($(window).scrollTop() + wHeight >= offBtm03){
			$hotbox03.addClass("pageShow");
		}*/
	});

	//首页banner处向下箭头锚点效果
	$(".p_pronextbtn").on("click",function(){
		var offTop = $(".s_offTop").offset().top,
			height = $nav.height();
		$("body,html").animate({scrollTop:offTop}, 300);
	});
});

// 选择热门户型风格
$(function(){
	var intx = $('.p_in_selbox>span');
	intx.click(function(){
		var inul = $(this).siblings('ul'),
			box = $(this).parent('div');
		if (inul.is(':hidden')) {
			inul.slideDown();
			box.css('border-radius','3px 3px 0 0');
		}else{
			inul.slideUp();
			box.css('border-radius','3px');
		};
	});
	$('.p_in_hxul').hover(function() {
		$(this).children('li').click(function() {
			$(this).parent('ul').siblings('span').text($(this).text());
			$(this).parent('ul').slideUp();
			$(this).parent('ul').parent('div').css('border-radius','3px');
		});
	}, function() {
		$(this).slideUp();
	});
});


/* 2015.08.25 sxk */
$(function(){
	$(".s_discuss>li:last").find(".s_discuss-border").css("height",0);

	$(".ly_iready").click(function(){
		if(!$(this).hasClass("clicked")){
			$(this).addClass("clicked");
		}else{
			$(this).removeClass("clicked");
		}
	});
	
	$(".s_hometj2").each(function(){
		scrollPic($(this),$(this).find(".s_hometjlist"),173,3000,5,$(this).find(".s_hometjprev"),$(this).find(".s_hometjnext"),$(this).find(".s_hometjpoint li"));
	});
	$(".s_hometj3").each(function(){
		scrollPic($(this),$(this).find(".s_hometjlist"),145,3000,6,$(this).find(".s_hometjprev"),$(this).find(".s_hometjnext"),$(this).find(".s_hometjpoint li"));
	});

	fadeBanner($(".s_designerslide"),$(".s_slidemenu li"));

	tabcard($(".s_fixedmenu li"),$(".s_homecont"));
});

function fadeBanner(obj,menus){
    var imgs = obj.children("li"),
        len = imgs.length,
        onIndex = 0;
    for(var i = 0; i < len; i++){
        imgs.css("z-index",len-i);
    }
    imgs.hide().eq(0).show();
    menus.eq(0).addClass("clicked");
    menus.mouseover(function(){
        var index = $(this).index();
        if(index != onIndex){
            imgs.eq(onIndex).stop(false,true).fadeOut(600);
            imgs.eq(index).stop(false,true).fadeIn(600,function(){
                menus.eq(index).addClass("clicked").siblings().removeClass("clicked");
                onIndex = index;
            });
        }
    });
    var timeid;
    obj.parent().hover(function(){
        clearInterval(timeid);
    },function(){
        timeid = setInterval(function(){
            if(onIndex < len-1){
                imgs.eq(onIndex).stop(false,true).fadeOut(600);
                imgs.eq(onIndex+1).stop(false,true).fadeIn(600,function(){
                    menus.eq(onIndex+1).addClass("clicked").siblings().removeClass("clicked");
                    onIndex++;
                });
            }else{
                imgs.eq(len-1).stop(false,true).fadeOut(600);
                imgs.eq(0).stop(false,true).fadeIn(600,function(){
                    menus.eq(0).addClass("clicked").siblings().removeClass("clicked");
                    onIndex = 0;
                });
            }
        },3000);
    }).trigger("mouseleave");
}
function tabcard(select,cont){
    var timeid;
    select.eq(0).addClass("clicked");
    cont.hide().eq(0).show();
    select.click(function(){
        var that = $(this);
        var index = that.index();
        that.addClass("clicked").siblings().removeClass("clicked");
        cont.hide().eq(index).show();
    });
}


//创建户型-创建成功调用点击切换
$(function(){
	var astr=$(".ly_successlist a"),
	 ulstr=$(".ly_successtab ul");
	tabclick(astr,ulstr,"ashow");
});

$(function(){
	$(".ly_creatclose").bind("click",function () {
		onclikclose("ly_creatmsg");
	});
});

$(function(){
	//完善楼盘信息调用输入字符个数
	checkMessage(300,"ly_creatarea","ly_number");
	//楼盘主页 滚动
	scrollRow($(".p_lp_scropicon"),$(".p_lp_scroul"),297*4,4000,4,$(".m_lp_prev"),$(".m_lp_next"));
});
//banner图
$(function(){
	banner($(".m_lp_list li"),$(".m_lp_cur ul"),$(".m_lp_cur"),$(".m_lp_wrapper"));
});

//index图片效果
$(function(){
	$(".p_in_picul").each(function(){
		fanImg($(this));
	});
});

$(function(){
	var lpImg1 = $(".m_lp_img1"),
        lpImg2 = $(".m_lp_img2"),
        lpImg3 = $(".m_lp_img3"),
        lpImg4 = $(".m_lp_img4"),
        lpImg5 = $(".m_lp_img5"),
        lpImg = $(".m_lp_img");

	lpImg1.css({
		"width":490,
		"height":374,
		"top":0,
		"left":0
	});
	lpImg2.css({
		"width":239,
		"height":181,
		"top":0,
		"left":501
	});
	lpImg3.css({
		"width":239,
		"height":181,
		"top":0,
		"left":751
	});
	lpImg4.css({
		"width":239,
		"height":181,
		"top":192,
		"left":501
	});
	lpImg5.css({
		"width":239,
		"height":181,
		"top":192,
		"left":751
	});
	function imgSmall($img){
		$img.animate({
			"width":239,
			"height":181
		});
	}
});
//我的楼盘图片效果
$(function(){
	$(".m_lp_rmRight").map(function(){
		var $imgs = $(this).children(".m_lp_img"),
		smallWidth = 239,
		smallHeight = 181,
		bigWidth = 490,
		bigHeight = 374,
		during = 300,
		boxWidth = $imgs.parent().width(),
		boxHeight = $imgs.parent().height(),
		timeid; //动画时间
		$imgs.on("mouseover",function(e){
			var $that = $(this);
			if(!$that.hasClass("bigPic")){
				clearTimeout(timeid);
				timeid = setTimeout(function(){
					if(!$imgs.is(":animated")){
						var index = $that.index(),
							$bigPic = $that.siblings(".bigPic"),
							bigIndex = $bigPic.index();
						var tops = new Array(),
							lefts = new Array()
							onCol = 0; //保存与this同列的元素
						for(var i = 0; i < $imgs.length; i++){
							tops[i] = $imgs.eq(i).position().top;
							lefts[i] = $imgs.eq(i).position().left;
							if(lefts[i] == $that.position().left && i != index){
								onCol = i;
							}
						}
						if(lefts[index] > lefts[bigIndex] && lefts[index] - lefts[bigIndex] < bigWidth + smallWidth){ //通过鼠标位置判断伸缩方向 ,大图在左侧中间无小图
							if(tops[onCol] > tops[index]){ //如果是上方元素 -- 右上
								$bigPic.css({
									"left" : lefts[bigIndex],
									"top" : tops[bigIndex],
									"width" : smallWidth,
									"height" : smallHeight
								});
								$imgs.eq(onCol).css({
									"left" : lefts[bigIndex],
									"top" : tops[onCol]
								});
								$that.css({
									"left" : lefts[index] + smallWidth - bigWidth,
									"top" : tops[bigIndex],
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}else{ //如果是下方元素
								$bigPic.css({
									"left" : lefts[bigIndex],
									"top" : tops[bigIndex] + bigHeight - smallHeight,
									"width" : smallWidth,
									"height" : smallHeight
								})

								$imgs.eq(onCol).css({
									"left" : lefts[bigIndex],
									"top" : tops[onCol]
								});

								$that.css({
									"left" : lefts[index] + smallWidth - bigWidth,
									"top" : tops[bigIndex],
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}
						}
						if(lefts[index] > lefts[bigIndex] && lefts[index] - lefts[bigIndex] > bigWidth + smallWidth){ //通过鼠标位置判断伸缩方向 ,大图在左侧中间有小图
							var midUp = 0, midDown = 0;
								for(var i = 0; i < $imgs.length; i++){ //获取夹在中间的两个元素
									if(lefts[i] > lefts[bigIndex] && lefts[i] < lefts[index]){
										if(tops[i] == tops[bigIndex]){
											midUp = i;
										}else{
											midDown = i;
										}
									}
								}
							if(tops[onCol] > tops[index]){ //如果是上方元素
								$bigPic.css({
									"left" : lefts[bigIndex],
									"top" : tops[bigIndex],
									"width" : smallWidth,
									"height" : smallHeight
								});

								$imgs.eq(onCol).css({
									"left" : lefts[midUp] + smallWidth - bigWidth,
									"top" : tops[onCol]
								});
								$imgs.eq(midDown).css({
									"left" : lefts[bigIndex],
									"top" : tops[midDown]
								});
								$imgs.eq(midUp).css({
									"left" : lefts[midUp] + smallWidth - bigWidth,
									"top" : tops[midUp]
								});
								$that.css({
									"left" : lefts[index] + smallWidth - bigWidth,
									"width" : bigWidth,
									"height" : bigHeight,
									"top" : tops[index]
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}else{ //如果是下方元素
								$bigPic.css({
									"left" : lefts[bigIndex],
									"top" : tops[bigIndex] + bigHeight - smallHeight,
									"width" : smallWidth,
									"height" : smallHeight
								});

								$imgs.eq(onCol).css({
									"left" : lefts[midDown] + smallWidth - bigWidth,
									"top" : tops[onCol]
								});
								$imgs.eq(midDown).css({
									"left" : lefts[midDown] + smallWidth - bigWidth,
									"top" : tops[midDown]
								});
								$imgs.eq(midUp).css({
									"left" : lefts[bigIndex],
									"top" : tops[midUp]
								});

								$that.css({
									"left" : lefts[index] + smallWidth - bigWidth,
									"top" : tops[bigIndex],
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}
						}
						if(lefts[index] < lefts[bigIndex] && lefts[bigIndex] - lefts[index] < 2*smallWidth){ //通过鼠标位置判断伸缩方向 ,大图在右侧中间无小图
							if(tops[onCol] > tops[index]){ //如果是上方元素
								$bigPic.css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth,
									"top" : tops[bigIndex],
									"width" : smallWidth,
									"height" : smallHeight
								});
								$imgs.eq(onCol).css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth
								});
								$that.css({
									"left" : lefts[index],
									"top" : 0,
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}else{ //如果是下方元素
								$bigPic.css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth,
									"top" : bigHeight - smallHeight,
									"width" : smallWidth,
									"height" : smallHeight
								})

								$imgs.eq(onCol).css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth
								});

								$that.css({
									"left" : lefts[index],
									"top" : 0,
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}
						}
						if(lefts[index] < lefts[bigIndex] && lefts[bigIndex] - lefts[index] > 2*smallWidth){ //通过鼠标位置判断伸缩方向 ,大图在右侧中间有小图
							var midUp = 0, midDown = 0;
								for(var i = 0; i < $imgs.length; i++){ //获取夹在中间的两个元素
									if(lefts[i] < lefts[bigIndex] && lefts[i] > lefts[index]){
										if(tops[i] == tops[bigIndex]){
											midUp = i;
										}else{
											midDown = i;
										}
									}
								}
							if(tops[onCol] > tops[index]){ //如果是上方元素
								$bigPic.css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth,
									"top" : tops[bigIndex],
									"width" : smallWidth,
									"height" : smallHeight
								});

								$imgs.eq(onCol).css({
									"left" : lefts[midUp] - smallWidth + bigWidth
								});
								$imgs.eq(midDown).css({
									"left" : lefts[bigIndex] - smallWidth + bigWidth
								});
								$imgs.eq(midUp).css({
									"left" : lefts[midUp] - smallWidth + bigWidth
								});
								$that.css({
									"left" : lefts[index],
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}else{ //如果是下方元素
								$bigPic.css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth,
									"top" : bigHeight - smallHeight,
									"width" : smallWidth,
									"height" : smallHeight
								});

								$imgs.eq(onCol).css({
									"left" : lefts[midUp] - smallWidth + bigWidth
								});
								$imgs.eq(midDown).css({
									"left" : lefts[midUp] - smallWidth + bigWidth
								});
								$imgs.eq(midUp).css({
									"left" : lefts[bigIndex] + bigWidth - smallWidth
								});

								$that.css({
									"left" : lefts[index],
									"top" : 0,
									"width" : bigWidth,
									"height" : bigHeight
								}).addClass("bigPic").siblings().removeClass("bigPic");
							}
						}
					}
				},300);
			}
		});
	});
});


// 20150901 pj
$(function(){
	$('.p_lp_xzleft').click(function(event) {
		var box = $(this).children('.p_lp_slide');
		if (box.is(':hidden')) {
			box.slideDown();
			$('.p_down').hide();
			$('.p_up').show()
		}else{
			box.slideUp();
			$('.p_down').show();
			$('.p_up').hide()
		};
		box.click(function(event) {
			event.stopPropagation();
		});
		event.stopPropagation();
	});
	$("body").click(function(){
		$('.p_lp_slide').slideUp();
		$('.p_down').show();
		$('.p_up').hide()
	});
	$('.p_lp_closex').click(function(){
		$(this).parent('.p_lp_xztip').hide();
	});
});


// 20150906 pj
$(function(){
	$('.p_hy_changjwt h6').click(function() {
		var word = $(this).next('.p_hy_cjword');
		if (word.is(':hidden')) {
			$('.p_hy_cjword').slideUp();
			$('.p_hy_changjwt .up').hide();
			$('.p_hy_changjwt .down').show();
			word.slideDown();
			$(this).find('.down').hide();
			$(this).find('.up').show();
		}else{
			word.slideUp();
			$(this).find('.down').show();
			$(this).find('.up').hide();
		};
	});
})

// 20150914 p
$(function(){
    $(".p_lp_rtop h5 strong,.p_pronumber strong").map(function(){
        var realText=$(this).text(),                            //获取字符串内容
            newText=[realText.length],                          //新建一个数组，数组长度为上边获取字符串的长度
            timeid,
            the=$(this);
        timeid=setInterval(function(){                          //间歇执行以下内容
            for(var i=0; i<realText.length; i++){
                if(/\d/.test(realText.charAt(i))){              //使用正则表达式获取字符串中的数字和符号
                    newText[i]=Math.floor(Math.random()*10);    //用数组保存对应的数字和符号，将数字改为随机数字
                }else{
                    newText[i]=realText.charAt(i);
                }
            }
            var lastText="";                                    //新建一个空字符串
            for(var j=0;j<newText.length;j++){
                lastText=lastText+newText[j];                   //将数组里的值通过累加变成字符串
            }
            the.text(lastText);                                 //在网页中输出新形成字符串
        },120);
        setTimeout(function(){
            clearInterval(timeid);                              //1s后清除上边间歇执行的内容，并显示真实字符串
            the.text(realText);
        },1500);
    });     //主要用到的知识：间歇方法setInterval,定时方法setTimeout,Math对象，取字符串中字符charAt(),string和array之间的转换...
});


$(function(){
	$('.p_lp_ckmore').click(function() {
		var offTop =  $(".s_homemain").offset().top;
		$("html,body").stop().animate({"scrollTop":offTop},300);
		$('.s_fixedmenu').find("li:contains('楼盘详情')").trigger('click');
	});
});

//瀑布流
$(function(){
	$("body").click(function(){
		if(!$(".m_wdlp_waterfall").parent().is(":hidden")){
			waterfall($(".m_wdlp_waterBox>li"),20);
		}
	});
});















